//package com.xmgps.bdt.infrastructure.config;
//
//import com.xmgps.bdt.domain.ycyg.ShipLocationInfo;
//import com.xmgps.bdt.infrastructure.config.TopicOptions;
//import org.apache.kafka.clients.admin.AdminClientConfig;
//import org.apache.kafka.clients.admin.NewTopic;
//import org.apache.kafka.clients.producer.ProducerConfig;
//import org.apache.kafka.common.serialization.StringSerializer;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.kafka.core.DefaultKafkaProducerFactory;
//import org.springframework.kafka.core.KafkaAdmin;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.kafka.core.ProducerFactory;
//import org.springframework.kafka.support.serializer.JsonSerializer;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 三亚海兰寰宇海洋信息科技
// * @author zeno.w
// * @date 2022/4/6
// */
//@Configuration
//public class KafkaConfig {
//
//    @Value("${zjxy-dtu-server.kafka.server-addrs}")
//    private String serverAddrs;
//
//    @Bean
//    @ConfigurationProperties(prefix="bokun-terminal-communication.ship-location.kafka-topic")
//    public TopicOptions shipLocationTopicOptions(){
//        return new TopicOptions();
//    }
//
//    @Bean
//    public NewTopic shipLocationTopic(@Qualifier("shipLocationTopicOptions") TopicOptions options){
//        return new NewTopic(options.getName(),options.getPartitionNum(),options.getReplication());
//    }
//
//    @Bean
//    public ProducerFactory<String, ShipLocationInfo> shipLocationInfDeDeDeoProducerFactory() {
//
//        Map<String, Object> factoryProps = new HashMap<>(5);
//        factoryProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,serverAddrs);
//        factoryProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
//        factoryProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
//        factoryProps.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "snappy");
//
//        return new DefaultKafkaProducerFactory<>(factoryProps);
//    }
//
//    @Bean
//    public KafkaTemplate<String, ShipLocationInfo> shipInfoKafkaTemplate(
//            @Qualifier("shipLocationInfDeDeDeoProducerFactory") ProducerFactory<String, ShipLocationInfo> factory) {
//        return new KafkaTemplate<>(factory);
//    }
//
//    @Bean
//    public KafkaAdmin kafkaAdmin() {
//        /** spring 的 autoconfig 实现会自动创建 topic。 */
//        Map<String, Object> configs = new HashMap<>();
//        configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG,serverAddrs);
//        return new KafkaAdmin(configs);
//    }
//}
